package com.health.adapter;

import java.util.List;

import com.health.R;
import com.health.model.PeopleType;
import com.health.tablebean.JTYSDoctorEvaluateBean;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 满意度列表数据
 * 
 * @author nova
 *
 */
public class SatisfactionAdapter extends BaseAdapter {

	private Context context;
	private List<JTYSDoctorEvaluateBean> list;

	public SatisfactionAdapter(Context context, List<JTYSDoctorEvaluateBean> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.jkjy_satisfaction_list, null);
			holder = new ViewHolder();
			holder.tv_myd = (TextView) convertView.findViewById(R.id.tv_myd);
			holder.tv_pjsj = (TextView) convertView.findViewById(R.id.tv_pjsj);
			holder.tv_pjr = (TextView) convertView.findViewById(R.id.tv_pjr);
			holder.tv_fwxm = (TextView) convertView.findViewById(R.id.tv_fwxm);
			holder.tv_fwys = (TextView) convertView.findViewById(R.id.tv_fwys);
			holder.tv_fwsj = (TextView) convertView.findViewById(R.id.tv_fwsj);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		try {
			setData(position, convertView, holder);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return convertView;
	}

	private void setData(int position, View convertView, ViewHolder holder) {
		// （0:满意,1:非常满意,2:不满意,4:一般,5:非常不满意）
		String state = list.get(position).getSatisfiedState();
		if (!TextUtils.isEmpty(state)) {
			if (state.equals("0")) {
				holder.tv_myd.setText("满意");
			} else if (state.equals("1")) {
				holder.tv_myd.setText("非常满意");
			} else if (state.equals("2")) {
				holder.tv_myd.setText("不满意");
			} else if (state.equals("4")) {
				holder.tv_myd.setText("一般");
			} else if (state.equals("5")) {
				holder.tv_myd.setText("非常不满意");
			}
		}

		holder.tv_pjsj.setText(list.get(position).getSatisfiedTime());
		holder.tv_pjr.setText(list.get(position).getCommentator());
		// (02：儿童、03：孕产妇(产前)、04：孕产妇(产后)、05：老年人、06：高血压、07：糖尿病、08：重症精神病)
		String serviceItem = list.get(position).getServiceItem();
		if (!TextUtils.isEmpty(serviceItem)) {
			if (serviceItem.equals("02")) {
				holder.tv_fwxm.setText("儿童");
			} else if (serviceItem.equals("03")) {
				holder.tv_fwxm.setText("孕产妇(产前)");
			} else if (serviceItem.equals("04")) {
				holder.tv_fwxm.setText("孕产妇(产后)");
			} else if (serviceItem.equals("05")) {
				holder.tv_fwxm.setText("老年人");
			} else if (serviceItem.equals("06")) {
				holder.tv_fwxm.setText("高血压");
			} else if (serviceItem.equals("07")) {
				holder.tv_fwxm.setText("糖尿病");
			} else if (serviceItem.equals("08")) {
				holder.tv_fwxm.setText("重症精神病");
			}else if (serviceItem.equals(PeopleType.GXB)){
				holder.tv_fwxm.setText("冠心病");
			}else if (serviceItem.equals(PeopleType.FJH)){
				holder.tv_fwxm.setText("脑卒中");
			}else if (serviceItem.equals(PeopleType.NCZ)){
				holder.tv_fwxm.setText("肺结核");
			}
		}

		holder.tv_fwys.setText(list.get(position).getCreater());
		holder.tv_fwsj.setText(list.get(position).getCreatedate());

		if (position % 2 == 0) {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
		} else {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.table_row_odd));
		}
	}

	private class ViewHolder {

		TextView tv_myd; // 满意度
		TextView tv_pjsj;// 评价时间
		TextView tv_pjr; // 评价人
		TextView tv_fwxm;// 服务项目
		TextView tv_fwys;// 服务医生
		TextView tv_fwsj;// 服务时间

	}

}
